import numpy as np

# Python代码示例：实现一个完整的神经网络层
class DenseLayer:
    def __init__(self, input_size, output_size, activation_function):
        # 初始化权重和偏置
        self.weights = np.random.randn(output_size, input_size) * 0.1
        self.bias = np.zeros((output_size, 1))
        self.activation = activation_function
    
    def forward(self, inputs):
        # 前向传播
        self.inputs = inputs
        self.z = np.dot(self.weights, inputs) + self.bias
        self.output = self.activation(self.z)
        return self.output
    
def sigmoid(x):
    return 1 / (1 + np.exp(-x))

# 示例：创建一个有3个输入、4个神经元的层
layer = DenseLayer(3, 4, sigmoid)
inputs = np.array([[0.5], [0.3], [0.8]])  # 3个输入特征
outputs = layer.forward(inputs)
print(f"层输出形状: {outputs.shape}")
print(f"层输出值: {outputs.flatten()}")